import Mock from 'mockjs'
var list = []
for(var i = 0; i<100; i++){
    list.push({
        id:Mock.mock('@guid'),
        num: i,
        name: Mock.mock('@cname()'),
        humnum:Mock.mock('@integer(10000000,99999999)'),
        typehum:Mock.mock('@integer(1,2)'),
        explain:Mock.mock('@integer(1,2)'),
        data:Mock.mock('@date'),
        boor:'是'
    })
}

import{ param2Obj } from '../utls/utilsDemo'
import Moment from 'moment'
import Vue from 'vue'
// import { config } from 'vue/types/umd'
Vue.prototype.moment = Moment
export default {
//查询接口返回数据
    getPoliceofficerData:(config)=>{
    var { keyword,page,pageSize } = param2Obj(config.url)
    var newArr = list.filter(item=>item.name.indexOf( keyword ) !== -1)
    
    var pageResult = newArr.filter((item,index)=>{
        return (page-1)*pageSize <= index && index < page*pageSize
    })
    return{
    code:200,
    msg:'请求成功',
    data:pageResult,
    total:list.length
    }
},
//删除接口返回数据
delData:(config)=>{
    var id = JSON.parse(config.body).id
    list.forEach((item,index) => {
        if(item.id == id){
            list.splice(index,1)
        }
    });
    return{
        code:200,
        msg:'请求成功',
        data:null
    }
},

    addData:config=>{
        console.log('111', config.body);
      
        var {name,humnum,typehum,explain,time,boor} = JSON.parse(config.body)
        var moment = require("moment");
        var timechage = moment(time).format("YYYY-MM-DD")
        console.log('222', time);

        list.unshift({
        id:Mock.mock('@guid'),
        num: i,
        name: name,
        humnum:humnum,
        typehum:typehum,
        explain:explain,
        data:timechage,
        boor:boor
        })
        return{
            code:200,
            msg:'添加成功',
            data:null
        }
    },
    uphangderData:config=>{
        var {id,name,humnum,typehum,explain,data,boor} = JSON.parse(config.body)
        list.forEach(item=>{
            if(item.id == id){
                // item就是我们查找的旧的值
                item.name = name
                item.humnum = humnum
                item.typehum = typehum
                item.explain = explain
                item.data = data
                item.boor = boor
            }
        })
            return{
                code:200,
                msg:'修改成功',
                data:null
            }
    }

}